<template>
  <div style="width: 100%; height: 100%">
    <div ref="chartDom" style="width: 100%; height: 100%"></div>
  </div>
  `
</template>
<script setup>
import { useRoute } from 'vue-router'
const router = useRoute()
console.log(router.query.name)
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'
import { getSiteDataByName } from '@/api/site'
const siteData = ref([])
var chartDom = ref()
onMounted(async () => {
  const { code, message, data } = await getSiteDataByName(router.query.name)
  console.log(data)
  if (code == 200) {
    siteData.value = data
    var myChart = echarts.init(chartDom.value)
    var option

    option = {
      title: {
        text: router.query.name,
        left: 'center',
      },
      tooltip: {
        trigger: 'item',
      },
      legend: {
        orient: 'vertical',
        left: 'left',
      },
      series: [
        {
          name: '电池统计',
          type: 'pie',
          radius: '70%',
          data: siteData.value,
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)',
            },
          },
        },
      ],
    }
    option && myChart.setOption(option)
  }
})
</script>

<style scoped></style>
